'use strict';

module.exports = {
  async up (queryInterface, Sequelize) {
    const { INTEGER, STRING, DATE, ENUM, TEXT } = Sequelize;
    await queryInterface.createTable('fava',{
      id: {
        type: INTEGER(20).UNSIGNED,
        primaryKey: true,
        autoIncrement: true
      },
      data: {
        type: TEXT,
        allowNull: false,
        defaultValue: '',
        comment: '内容'
      },
      type: {
        type: ENUM,
        values: ['emoticon', 'text', 'image', 'video', 'audio', 'card'],
        allowNull: false,
        defaultValue: 'text',
        comment: '类型',
      },
      options: {
        type: TEXT,
        allowNull: false,
        defaultValue: '',
        comment: '其他参数'
      },
      user_id: {
        type: INTEGER(20).UNSIGNED,
        allowNull: false,
        comment: '用户id',
        references: {
          model: 'user',
          key: 'id'
        },
        onUpdate: 'restrict', // 更新时操作
        onDelete: 'cascade' // 删除时操作
      },
      created_at: DATE,
      updated_at: DATE
    });
  },

  async down (queryInterface, Sequelize) {
    await queryInterface.dropTable('fava')
  }
};
